import { contextBridge, ipcRenderer } from 'electron';

let { webContentsId } = ipcRenderer.sendSync('___!boot');
if (!webContentsId) {
  webContentsId = 2;
}

contextBridge.exposeInMainWorld('SDWebUI_ImageQuickSend', {
  getWebContentId: () => ipcRenderer.sendSync('LiteLoader.SDWebUI_ImageQuickSend.getWebContentId'), // 获取当前webContentsId
  getConfig: () => ipcRenderer.invoke('LiteLoader.SDWebUI_ImageQuickSend.getConfig'),
  getOptions: () => ipcRenderer.sendSync('LiteLoader.SDWebUI_ImageQuickSend.getOptions'),
  getServerStatus: () => ipcRenderer.sendSync('LiteLoader.SDWebUI_ImageQuickSend.getServerStatus'),
  setConfig: (newConfig: any) => ipcRenderer.invoke('LiteLoader.SDWebUI_ImageQuickSend.setConfig', newConfig),
  onNewImage: (callback: (url: string) => void) => ipcRenderer.on('LiteLoader.SDWebUI_ImageQuickSend.sendImage', (_event, url) => callback(url)),
});